package com.example.pda.ui.list;

import com.example.pda.common.BaseViewModel;
import com.example.pda.common.Utils;
import com.example.pda.data.Result;
import com.example.pda.data.model.GoodItem;
import com.example.pda.data.model.Inventory;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import androidx.lifecycle.MutableLiveData;

public class OrderListViewModel extends BaseViewModel {

    private final MutableLiveData<List<Inventory>> djhData = new MutableLiveData<>();

    public MutableLiveData<List<Inventory>> getDjhData() {
        return djhData;
    }

    public void loadOrder(boolean isShowDialog, String type) {
        enqueue(api.getDjgList(type), isShowDialog, new ResultCallback<List<Inventory>>() {
            @Override
            public void onSuccess(List<Inventory> inventories) {
                djhData.setValue(inventories);
            }

            @Override
            public void onError(int code, String msg) {
                getToast().setValue(msg);
            }
        });
//        String str = "{" +
//                "\"msg\": \"操作成功\"," +
//                "\"code\": 0," +
//                "\"data\": [" +
//                "{" +
//                "\"djh\": \"DH171110001\"," +
//                "\"billType\": \"23\"," +
//                "\"billTypeName\": \"采购入库\"" +
//                "}," +
//                "{" +
//                "\"djh\": \"SA230419002\"," +
//                "\"billType\": \"4455\"," +
//                "\"billTypeName\": \"材料出库\"" +
//                "}," +
//                "{" +
//                "\"djh\": \"DC191024001\"," +
//                "\"billType\": \"5X\"," +
//                "\"billTypeName\": \"调拨出库\"" +
//                "}" +
//                "]" +
//                "}";
//        Result<List<Inventory>> list = new Gson().fromJson(str, new TypeToken<Result<List<Inventory>>>() {
//        }.getType());
//
//        if(list != null && list.getCode().equals("0")){
//            djhData.setValue(list.getData());
//        }
    }

    public final MutableLiveData<List<GoodItem>> mDataBean = new MutableLiveData<>();

    public void loadDjhItmByDjh(String djh) {
        enqueue(api.getDjhItemByDjh(djh), true, new ResultCallback<List<GoodItem>>() {
            @Override
            public void onSuccess(List<GoodItem> goodItem) {
                mDataBean.setValue(goodItem);
            }

            @Override
            public void onError(int code, String msg) {
                Utils.getInstance().showToast(msg);
            }
        });
    }
}